home *** CD-ROM | disk | FTP | other *** search
- /*
- File: DragUtils.cp
-
- Contains: Useful utility functions when using the Drag Manager.
-
- Written by: Nitin Ganatra
-
- Copyright: © 1993-1995 by Dave Falkenburg, all rights reserved.
-
- Change History (most recent first):
-
- <3> 1/3/95 DRF Replace everything with Nitin’s code.
- <2> 11/12/94 DRF Added #include to pick up function prototype.
- <1> 9/9/94 DRF first checked in
- */
-
- #include "Sprocket.h"
-
- #include <Folders.h>
-
- #include <QuickDraw.h>
- #include <Folders.h>
- #include <Files.h>
- #include <Drag.h>
-
-
- //-----------------------------------------------------------------------------
- // The standard UI for dragged objects is a 1-pixel outline of
- // region to be dragged.
- // Given any region, this will turn it into the 1-pixel outline.
- //-----------------------------------------------------------------------------
- void MakeDragOutlineRegion(RgnHandle theRgn)
- {
- RgnHandle tempRgn;
-
- tempRgn = NewRgn();
-
- if (tempRgn != NULL) {
- CopyRgn(theRgn, tempRgn);
- InsetRgn(tempRgn, 1, 1);
- DiffRgn(theRgn, tempRgn, theRgn);
- DisposeRgn(tempRgn);
- }
- }
-
-
- //-----------------------------------------------------------------------------
- // GetDropDirectory
- //
- // Given a DragReference, this returns an FSSpec for the directory where the
- // item was dropped.
- //-----------------------------------------------------------------------------
- OSErr GetDropDirectory(DragReference theDrag, FSSpecPtr dirSpec)
- {
- OSErr returnCode;
- AEDesc theDesc;
-
- returnCode = GetDropLocation(theDrag, &theDesc);
-
- if ((theDesc.dataHandle != nil)
- && (returnCode == noErr)) {
- AEDesc newDesc;
-
- returnCode = AECoerceDesc(&theDesc, typeFSS, &newDesc);
-
- if (returnCode == noErr) {
- BlockMoveData(*newDesc.dataHandle, dirSpec, sizeof(FSSpec));
- (void) AEDisposeDesc(&newDesc);
- }
-
- (void) AEDisposeDesc(&theDesc);
- }
-
- return returnCode;
- }
-
-
- //-----------------------------------------------------------------------------
- // DragLandedInTrash
- //
- // If this drag landed in the trash (compared using FindFolder) this will
- // return true.
- //-----------------------------------------------------------------------------
- Boolean DragLandedInTrash(DragReference theDrag)
- {
- OSErr returnCode;
- FSSpec dirSpec;
- short trashVol;
- long trashDirID;
- Boolean wasTrashed;
-
- wasTrashed = false;
- returnCode = GetDropDirectory(theDrag, &dirSpec);
-
- if (returnCode == noErr) {
- returnCode = FindFolder(0, kTrashFolderType, false, &trashVol, &trashDirID);
-
- if (returnCode == noErr) {
- CInfoPBRec catInfo;
- DirInfo *dpb = (DirInfo *)&catInfo;
-
- dpb->ioCompletion = nil; // Find the dirID of the drop location,
- dpb->ioNamePtr = dirSpec.name; // not its parent.
- dpb->ioVRefNum = dirSpec.vRefNum;
- dpb->ioDrDirID = dirSpec.parID;
- dpb->ioFDirIndex = 0;
-
- returnCode = PBGetCatInfoSync((CInfoPBPtr)dpb);
-
- if ((trashVol == dirSpec.vRefNum)
- && (trashDirID == dpb->ioDrDirID))
- wasTrashed = true;
- }
- }
-
- return wasTrashed;
- }
-